<?php
class Form{

	private $_elements;	

	function open($listOfElements){
		if(is_array($listOfElements)){
			$this->_elements = $listOfElements;
		}
	}
	
	private static function _isValidEmail($name){
		return (bool) filter_var($name, FILTER_VALIDATE_EMAIL);
	}

	private static function _cleanString($string){
	    return stripslashes($string);
	}
	
	public function get($key){
		if(isset($_POST[$key])){
			return $this->_cleanString($_POST[$key]);
		}
		return false;
	}
	
	public function isValidElement($key,$req){
		$value = $this->get($key);
		
		if($value==false && $req)
			return false;
		if($value==false && !$req)
			return true;
			
		if($key=="email")
			return $this->_isValidEmail($value);
		
		return !empty($value);
	}
	
	public function isValidForm(){
		foreach ($this->_elements as $key => $value) {
			if(!$this->isValidElement($key,$value)){
				return false;
			}
		}
		return true;
	}	
}
?>